package net.scalan.jpa.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

@Entity
public class DBStation implements Serializable {

    private static final long serialVersionUID = 1L;

    //==========================================================================
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    //==========================================================================
    @Column
    private String name;

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch=FetchType.LAZY)
    @JoinColumn(name = "station_id", referencedColumnName = "id")
    private List<DBELink> elinks = new ArrayList<DBELink>();

    /**
     * @return the elinks
     */
    public List<DBELink> getElinks() {
        return elinks;
    }

    /**
     * @param elinks the elinks to set
     */
    public void setElinks(List<DBELink> elinks) {
        this.elinks = elinks;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch=FetchType.LAZY)
    @JoinColumn(name = "station_id", referencedColumnName = "id")
    private List<DBSchema> schemas = new ArrayList<DBSchema>();

    /**
     * @return the schemas
     */
    public List<DBSchema> getSchemas() {
        return schemas;
    }

    /**
     * @param schemas the schemas to set
     */
    public void setSchemas(List<DBSchema> schemas) {
        this.schemas = schemas;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch=FetchType.LAZY)
    @JoinColumn(name = "station_id", referencedColumnName = "id")
    private List<DBStationCabinet> cabinets = new ArrayList<DBStationCabinet>();

    /**
     * @return the cabinets
     */
    public List<DBStationCabinet> getCabinets() {
        return cabinets;
    }

    /**
     * @param cabinets the cabinets to set
     */
    public void setCabinets(List<DBStationCabinet> cabinets) {
        this.cabinets = cabinets;
    }

    //==========================================================================
    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch=FetchType.LAZY)
    @JoinColumn(name = "station_id", referencedColumnName = "id")
    private List<DBLogicalStationObject> logicalStationObject = new ArrayList<DBLogicalStationObject>();

    /**
     * @return the schemas
     */
    public List<DBLogicalStationObject> getLogicalStationObject() {
        return logicalStationObject;
    }

    /**
     * @param schemas the schemas to set
     */
    public void setLogicalStationObject(List<DBLogicalStationObject> logicalStationObject) {
        this.logicalStationObject = logicalStationObject;
    }

    //==========================================================================
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DBStation)) {
            return false;
        }
        DBStation other = (DBStation) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "net.scalan.jpa.model." + this.getClass().getName() + "[id=" + id + "]";
    }

}
